package com.gxa.hotel.sso.repository;


import com.gxa.hotel.sso.entity.User;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.RepositoryDefinition;

import java.util.List;

/**
 * CrudRepostory: 有JPA声明,hibernate实现的基础crud操作的持久化对象
 * 通过创建接口并继承CrudRepositody,就获取了基本的api(crud)操作
 */
@RepositoryDefinition(domainClass = User.class,idClass = Long.class)
public interface UserRepository extends CrudRepository<User,Long> {
    /**
     * 通过手机号获取用户信息
     */

    User findByPhoneEquals(String phone);

    List<User> findByNameStartingWith(String name);

    List<User> findByPhoneIn(String... phone);
    Page<User> findByNameContains(String name, Pageable pageable);
    @Query(nativeQuery = true,value = "select count(*)from tb_user")
            Integer getCount();
}
